$(function () {
    /*初始化*/
    init();
});

function init() {
    $('#workTable').bootstrapTable({
        method: 'get',  //发送方式
        url: `http://192.168.59.3:8082/console/shopping/findFirstMaterielIsLeaf`,  // 接口路径 材料
        onLoadSuccess: function (data) {
            console.log(data);
            console.log("材料加载成功。。。。");
        }
    });
    $('#workTable1').bootstrapTable({
        method: 'get',  //发送方式
        url: `http://192.168.59.3:8082/console/shopping/findFirstDeviceIsLeaf`,  // 接口路径 设备
        onLoadSuccess: function (data) {
            console.log(data);
            console.log("设备加载成功。。。。");
        }
    });
    $('#workTable2').bootstrapTable({
        method: 'get',  //发送方式
        url: `http://192.168.59.3:8082/console/shopping/findFirstFacilityIsLeaf`,  // 接口路径 设施
        onLoadSuccess: function (data) {
            console.log(data);
            console.log("设施加载成功。。。。");
        }
    });
}
function responseHandler(res) {
    console.log(res);
    var needData = {
        rows: res.data.list,
        total: res.data.total
    };
    return needData;
}

function indexFmt(val, row, index) {
    return index + 1;
}

function workTableQuery(params) {
    params["pageNum"] = (params.offset / params.limit) + 1;
    params.pageSize = params.limit;
    return params;
}

/*******点击选择地区，获取省份，市的信息*********/
function city() {
//	 获取所有的省份
    $.ajax({
        type: "get",
        url: "http://192.168.59.3:8082/console/basedata/area/provincelist",
        contentType: "application/json",
        success: function (data) {
            console.log(data);
            var data1 = JSON.parse(data).data;
            console.log(data1);

            var sel1 = document.getElementsByClassName("prov")[0];
            var sel2 = document.querySelector(".city");
            console.log(sel1);
            for (var i = 0; i < data1.length; i++) {
                var optionObj = document.createElement('option');
                optionObj.innerHTML = data1[i].province;
                optionObj.value = data1[i].provinceid;
                sel1.appendChild(optionObj);
            }
            //   获取所有的市
            $.ajax({
                type: "get",
                url: "http://192.168.59.3:8082/console/basedata/area/citylist",
                contentType: "application/json",
                success: function (data) {
                    console.log(data);
                    var data2 = JSON.parse(data).data;
                    console.log(data2);
                    sel1.onchange = function () {
                        for (var i = 0; i < sel2.children.length; i++) {
                            sel2.removeChild(sel2.children[i]);
                            i--;
                        }
                        for (var k = 0; k < data2.length; k++) {
                            if (sel1.value == data2[k].father) {
                                var optionObj = document.createElement('option');
                                optionObj.innerHTML = data2[k].city;
                                optionObj.value = data2[k].cityid;
                                sel2.appendChild(optionObj);
                            }
                        }
                    }
                },
                error: function (err) {
                    console.log(err);
                }
            });
        },
        error: function (err) {
            console.log(err);
        }
    });

}
